# Copyright (c) 2021-2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

panda_ets_interop_js_test(ets_interop_js_test_promise1
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/run_promise_test.js
    LAUNCHER_ARGS "testPendingPromise"
)

panda_ets_interop_js_test(ets_interop_js_test_promise2
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/run_promise_test.js
    LAUNCHER_ARGS "testResolvedPromise"
)

panda_ets_interop_js_test(ets_interop_js_test_promise3
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/run_promise_test.js
    LAUNCHER_ARGS "testRejectedPromise"
)

panda_ets_interop_js_test(ets_interop_js_test_promise4
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/run_promise_test.js
    LAUNCHER_ARGS "testThenBeforeResolve"
)

panda_ets_interop_js_test(ets_interop_js_test_promise5
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/run_promise_test.js
    LAUNCHER_ARGS "testPromiseEmptyThen"
)

panda_ets_interop_js_test(ets_interop_js_test_promise6
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/run_promise_test.js
    LAUNCHER_ARGS "testPromiseChain"
)

panda_ets_interop_js_test(ets_interop_js_test_promise_catch_finally_chain
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/run_promise_test.js
    LAUNCHER_ARGS "testPromiseCatchFinallyChain"
)

panda_ets_interop_js_test(ets_interop_js_test_resolve_promise_then_finally
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/run_promise_test.js
    LAUNCHER_ARGS "testResolvePromiseThenFinally"
)

panda_ets_interop_js_test(ets_interop_js_test_reject_promise_then_finally
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/run_promise_test.js
    LAUNCHER_ARGS "testRejectPromiseThenFinally"
)

panda_ets_interop_js_test(ets_interop_js_test_promise7
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testReturnPromise" "Panda" 1
)

panda_ets_interop_js_test(ets_interop_js_test_promise8
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testReturnPromiseFromAsync" "Panda" 3
)

panda_ets_interop_js_test(ets_interop_js_test_promise9
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_pending_promise_to_js_test.js
    LAUNCHER_ARGS "then"
)

panda_ets_interop_js_test(ets_interop_js_test_promise10
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_pending_promise_to_js_test.js
    LAUNCHER_ARGS "await"
)

# panda_ets_interop_js_test(ets_interop_js_test_promise11
#     ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
#     JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/await_js_promise.js
#     LAUNCHER_ARGS "pending"
# )

# panda_ets_interop_js_test(ets_interop_js_test_promise12
#     ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
#     JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/await_js_promise.js
#     LAUNCHER_ARGS "resolved"
# )

panda_ets_interop_js_test(ets_interop_js_test_await_promise
    ETS_SOURCES ${INTEROP_JS_TESTS_SOURCE_DIR}/promise/promise_tests.ets
    JS_LAUNCHER ${INTEROP_JS_TESTS_SOURCE_DIR}/promise/run_promise_test.js
    LAUNCHER_ARGS "testAwaitPromise"
)

panda_ets_interop_js_test(ets_interop_js_test_async_bool
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testAsyncBoolean" true 1
)

panda_ets_interop_js_test(ets_interop_js_test_async_byte
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testAsyncByte" 127 1
)

panda_ets_interop_js_test(ets_interop_js_test_async_char
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testAsyncChar" "x" 1
)

panda_ets_interop_js_test(ets_interop_js_test_async_short
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testAsyncShort" 32767 1
)

panda_ets_interop_js_test(ets_interop_js_test_async_int
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testAsyncInt" 5 1
)

panda_ets_interop_js_test(ets_interop_js_test_async_long
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testAsyncLong" 9223372036854775807 1
)

panda_ets_interop_js_test(ets_interop_js_test_async_float
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testAsyncFloat" 3.14 1
)

panda_ets_interop_js_test(ets_interop_js_test_async_double
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testAsyncDouble" 3.2 1
)

panda_ets_interop_js_test(ets_interop_js_test_async_string
    ETS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/promise_tests.ets
    JS_LAUNCHER ${CMAKE_CURRENT_LIST_DIR}/return_promise_to_js_test.js
    LAUNCHER_ARGS "testAsyncString" "Panda" 1
)
